package edu.nf.supermarket.web.controller.app;

import edu.nf.supermarket.base.BaseController;
import edu.nf.supermarket.entity.Commodity;
import edu.nf.supermarket.entity.Orders;
import edu.nf.supermarket.result.ResultVO;
import edu.nf.supermarket.service.CommodityService;
import edu.nf.supermarket.service.OrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yjj
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/commodity")
public class CommodityController extends BaseController {
    @Autowired
    private CommodityService commodityService;
    /**
     * 根据id查询商品详情
     *
     * @param commodityId
     * @return
     */
    @GetMapping("/findCommodityById")
    public ResultVO<Commodity> findCommodityById(@RequestParam("id") Integer commodityId) {
        return success(commodityService.findCommodityById(commodityId));
    }

    /**
     * 直接购买商品生成订单
     */
    @GetMapping("/buyCommodity")
    public ResultVO<String> buyCommodity(@RequestParam("userId") Integer userId,
                                         @RequestParam("id") Integer commodityId,
                                         @RequestParam("num") Integer commodityNum,
                                         @RequestParam("spec1" ) String spec1,
                                         @RequestParam("spec2") String spec2) {
        commodityService.buyCommodity(userId, commodityId, commodityNum, spec1, spec2);
        return success();
    }
    /**
     * 商品查询
     */
    @GetMapping("/search")
    public ResultVO<List<Commodity>> findCommodityByName(@RequestParam("keyword") String commodityName) {
        return success(commodityService.findCommodityByName(commodityName));
    }


}
